package com.health.trans.processor.listener;

import lombok.Getter;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author nqlz
 */
public class ItemCountItemStream implements ItemStream {
    @Getter
    private final AtomicLong doneCount = new AtomicLong(0);

    @Override
    public void open(ExecutionContext executionContext) throws ItemStreamException {
    }

    @Override
    public void update(ExecutionContext executionContext) throws ItemStreamException {
        Object o = executionContext.get("JpaPagingItemReader.read.count");
        if (o != null) {
            doneCount.set(Long.parseLong(o.toString()));
        }
    }

    @Override
    public void close() throws ItemStreamException {

    }
}
